/**
 * 
 */
package ar.edu.unq.svnpermission.provider;

import java.util.ArrayList;
import java.util.Iterator;

import org.apache.wicket.Component;
import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import ar.edu.unq.svnpermission.domain.Folder;
import ar.edu.unq.svnpermission.domain.Permission;
import ar.edu.unq.svnpermission.ui.model.FolderDetail;
import ar.edu.unq.svnpermission.ui.model.Folders;
import ar.edu.unq.svnpermission.ui.model.Permissions;

/**
 * @author nicolas
 */
public class PermissionDataProvider extends SortableDataProvider<Permission> {
	private static final long serialVersionUID = 1L;
	private FolderDetail folderDetail;
	private Component panel;
	private Folder selectedFolder;
	
	public PermissionDataProvider(Folder folder)
	{
		//this.panel = panel;		
		//this.folderDetail = new FolderDetail(((Folders)panel.getParent().getDefaultModelObject()).getSelectedFolder());
		this.selectedFolder = folder;
	}

	public Iterator<Permission> iterator(int first, int count) {
		//return this.getFolderDetail() == null ? new ArrayList<Permission>().iterator() : ;
		return new Permissions(selectedFolder).getAll().iterator();
	}

	public int size() {
		//return  this.getFolderDetail() == null ? 0 : this.getFolderDetail().getPermission().size();
		return new Permissions(selectedFolder).getAll().size();
	}

	public IModel<Permission> model(Permission object) {
		return new Model<Permission>(object);
	}

	protected FolderDetail getFolderDetail() {
		//if (this.folderDetail == null && this.panel.getPage().getDefaultModelObject()!=null) {
		//	this.folderDetail = new FolderDetail(((Folders)this.panel.getDefaultModelObject()).getSelectedFolder());
		//}
		return this.folderDetail;
	}
	

}
